"""
train
| Seq1
| | img1/*.jpg
| | seqinfo.ini
| | gt/gt.txt
请你根据这个结构，将train映射到./MoTRv2/train中，除了gt.txt不映射其他的txt
使用Linux的软连接
"""

import os
import shutil
from typing import List


def handle_profile(
    source_path: str, target_path: str = "./MoTRv2", profile_name: str = "train"
):
    source_path = os.path.abspath(source_path)
    target_path = os.path.abspath(target_path)

    source_path = os.path.join(source_path, profile_name)
    target_path = os.path.join(target_path, profile_name)

    file_path_list: List[str] = []

    for root, dirs, files in os.walk(source_path):
        for file in files:
            if file.endswith(".txt") and file != "gt.txt":
                continue
            file_path_list.append(os.path.join(root, file))

    for file_path in file_path_list:
        target_file_path = file_path.replace(source_path, target_path)
        target_dir_path = os.path.dirname(target_file_path)
        os.makedirs(target_dir_path, exist_ok=True)
        os.symlink(file_path, target_file_path)


def main():
    base_dir="/home/konghaomin/Datasets/MaritimeTrack_Full_Same_73/DanceTrack"
    profiles = ["train", "val", "test"]
    
    source_path= source_path=os.path.join(base_dir,"")
    target_path=target_path=os.path.join(base_dir,"MoTRv2")
    
    if os.path.exists(target_path):
        shutil.rmtree(target_path)
        
    target_path=os.path.join(target_path,"DanceTrack")
    
    for profile in profiles:
        handle_profile(
           source_path=source_path, 
                    target_path=target_path   , 
                    profile_name=profile
                       )


if __name__ == "__main__":
    main()
